<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<p>用户名:<input type="text" name="name" value="" /><span id="rep"></span> </p>
	<p> <input type="submit" value="提交" /> </p>
</body>
<script type="text/javascript">
	var inp = document.getElementsByTagName('input')[0];
	inp.onblur = function(){
		var xhr = new XMLHttpRequest();
		xhr.open('get','2.php?name=' + inp.value, true);
		xhr.send(null);
		var sp = document.getElementById('rep');
		xhr.onreadystatechange = function(){
			if(this.responseText == 1){
				sp.innerHTML = 'YES';
			}else{
				sp.innerHTML = 'NO';
			}
		}
	}
</script>
</html>